<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button>get</button>
    <button>post</button>
</body>
<script>
    const btns = document.querySelectorAll("button");
	btns[0].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.open("get","http://zhangpeiyue.com/sum?a=10&b=20");
		xhr.send();
		xhr.onload = function(){
			console.log(xhr.response);
        }
    }
	btns[1].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.open("post","http://127.0.0.1/sum");
		xhr.setRequestHeader("Content-Type","application/json");
		xhr.setRequestHeader("a","1");
		xhr.send(JSON.stringify({
            a:1,
            b:2
        }));
		xhr.onload = function(){
			console.log(xhr.response);
		}
    }
</script>
</html>